package com.lp.user.control;

import com.lp.common.Result;
import com.lp.common.base.BaseController;
import com.lp.user.dto.Product;
import com.lp.user.service.ProductService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @Author: zhangzhiqiang
 * @Date: 2019/4/18 15:37
 * @Desc:
 */
@RestController
@Api(value = "商品相关的api")
@RequestMapping(value = "/product")
public class ProductController  extends BaseController {
    @Autowired
    private ProductService productServiceImpl;

    @ApiOperation(value="通过参数获取商品信息", notes="通过参数获取商品信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "当前记录的主键", required = true, dataType = "integer",paramType="query" ),
    })
    @RequestMapping(value = "/getProduct", method = RequestMethod.GET)
    public Result getProductInfo(Integer pid) {
        return productServiceImpl.getProductInfo(pid);
    }


    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ApiOperation(value="获取商品列表", notes="获取商品列表")
    @ApiResponses({
            @ApiResponse(code=200,message = "请求成功"),
            @ApiResponse(code=404,message="请求失败")
    })
    public Result getProductList() {
        return productServiceImpl.getProductInfos(null);
    }


    @ApiOperation(value="保存(新增)商品信息", notes="保存(新增)商品信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "productName", value = "商品名称", required = true, dataType = "string",paramType="query" ),
            @ApiImplicitParam(name = "productDesc", value = "商品描述 ", required = true, dataType = "string",paramType="query" ),
            @ApiImplicitParam(name = "productImgUrl", value = "商品图片地址", required = true, dataType = "string",paramType="query" ),
            @ApiImplicitParam(name = "enabled", value = "是否有效", required = true, dataType = "tinyint",paramType="query",defaultValue="1",allowableValues="1,0",example="1.有效0.无效")
    })
    @RequestMapping(value = "/saveProductInfo", method = RequestMethod.POST)
    public Result saveProductInfo(Product product) {
        return productServiceImpl.saveProductInfo(product);
    }


    @ApiOperation(value="修改商品信息", notes="修改商品信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "当前记录的主键", required = true, dataType = "integer",paramType="query" ),
            @ApiImplicitParam(name = "enabled", value = "是否有效", required = true, dataType = "tinyint",paramType="query",defaultValue="1",allowableValues="1,0",example="1.有效0.无效")
    })
    @RequestMapping(value = "/updateProductInfo", method = RequestMethod.POST)
    public Result updateUserInfo(Product product) {
        Result result=productServiceImpl.updateProductInfo(product);
        return result;
    }

    @ApiOperation(value="分页查找商品信息描述", notes="分页查找商品信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currrentPage", value = "当前页数", required = true, dataType = "integer",paramType="query" )
    })
    @ApiResponses({
            @ApiResponse(code=200,message = "nextPage：下一个页<br>previousPage:上一页<br>count：总条数<br>pageTotal:总页数<br>end：1没有下一页0.还有下一页<br>dataCount当前页的记录数"),
    })
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public Result page(Integer currrentPage )throws Exception {
        return productServiceImpl.getPage(currrentPage);
    }



}
